﻿@{
    ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>
@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
}

<!--  单选按钮 取值 赋值-->
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>


<table class="layui-table">
    <tr>
        <td>性别</td>
        <td>

            <input type="radio" name="sex" value="0" /> 男
            <input type="radio" name="sex" value="1" /> 女
            <input type="radio" name="sex" value="2" /> 未知

            <input type="button" name="name" value="您选择的性别" onclick="getSex()" />
        </td>
    </tr>

    <tr>
        <td>
        </td>
        <td>
        </td>
    </tr>
    <tr>
        <td>
            专业阶段
        </td>
        <td>
            <select id="jieduan">
                @*   <option value="1">专高1</option>
                <option value="2">专高2</option>
                <option value="3">专高3</option>
                <option value="4">专高4</option>
                <option value="5">专高5</option>
                <option value="6">专高6</option> *@
            </select>
            <input type="button" name="name" value="您选择的阶段" onclick="getJieduan()" />
        </td>
    </tr>
    <tr>
        <td>
        </td>
        <td>
        </td>
    </tr>
    <tr>
        <td>
            所学技术
            <input type="checkbox" id="checkAll" onclick="checkAll()" value="全选" /> 全选
            @* <input type="checkbox" id="UncheckAll" value="反选" /> 反选 *@
        </td>
        <td>
            <input type="checkbox" name="tech" class="techck" onclick="NocheckAll()" value="WebAPI" />WebAPI
            <input type="checkbox" name="tech" class="techck" onclick="NocheckAll()" value="LayUI" />LayUI
            <input type="checkbox" name="tech" class="techck" onclick="NocheckAll()" value="MVC" />MVC
            <input type="checkbox" name="tech" class="techck" onclick="NocheckAll()" value="C#" />C#
            <input type="checkbox" name="tech" class="techck" onclick="NocheckAll()" value="轮播图" />轮播图
            <input type="checkbox" name="tech" class="techck" onclick="NocheckAll()" value="FenYe" />FenYe

            <input type="button" name="name" value="您选择的技术" onclick="getTech()" />

        </td>
    </tr>
</table>

<script>

    var sex = -1;
    var xuanzhongjiesuan = 5;
    $(function () {
        ajax_user();//模拟调用接口
        getJieduanList();//初始化下拉列表
    });

    function getJieduanList() {
        var jieduans = [
            { name: "专高1", value: 1 },
            { name: "专高2", value: 2 },
            { name: "专高3", value: 3 },
            { name: "专高4", value: 4 },
            { name: "专高5", value: 5 },
            { name: "专高6", value: 6 }];//模拟调用webapi


        $("#jieduan").empty();
        $(jieduans).each(function (i, obj) {
            if (obj.value == xuanzhongjiesuan) {//默认选中专高3
                $("#jieduan").append("<option value='" + obj.value + "' selected>" + obj.name + "</option>");
            } else {
                $("#jieduan").append("<option value='" + obj.value + "'>" + obj.name + "</option>");
            }
        });
    }

    function ajax_user() {
        var user = { sex: 1, jieduan: 5 } //假装调用接口取得的值
        $("input[name='sex'][value=" + user.sex + "]").prop("checked", true);
        // $("input[name='sex'][value='1']").prop("checked", "checked");



    }


    function getSex() {
        var sex = $("input[name='sex']:checked").val();//取值
        alert(sex);
    }

    function getJieduan() {
        var xuanzhong = $("#jieduan").val();//下拉列表选中的值  取值
        alert(xuanzhong);
    }

    function getTech() {
        //你要取出所有复选框的选中元素集合
        //循环取出被选中的值

        var techs = [];
        $("input[name='tech']:checked").each(function () {
            techs.push($(this).val());
        });

        alert(techs.join(","));
    }

    function checkAll() {
        var qx = $("#checkAll").prop("checked");

        $(".techck").prop("checked", qx);

    }
    function NocheckAll() {
        var count = $(".techck").length;
        var count2 = $(".techck:checked").length;
        $("#checkAll").prop("checked", count == count2)

    }
</script>